Skip to content

Conversation

@JM-Lab
Copy link
Contributor

@JM-Lab JM-Lab commented Nov 21, 2023

  • Add OpenAI Stream Client implementation.
  • Add openAiStreamClient test in ClientIT.

Resolves #116

@making
Copy link
Member

making commented Nov 22, 2023

This PR is very specific to the openai-java implementation and does not resolve #116 .

@JM-Lab
Copy link
Contributor Author

JM-Lab commented Nov 22, 2023

I apologize for the confusion. The intention of this pull request was to add stream support to spring-ai's AiClient, inspired by the implementation in openai-java. This differs from the request in issue #116, which was specifically for an implementation not dependent on openai-java.

To meet the requirements of #116, it seems necessary to manually write all subclasses related to ChatCompletionsRequest, response classes, and SSE response classes. Accordingly, I will submit a new pull request with the necessary modifications.

If you have any further questions or suggestions, please feel free to let me know.

@tzolov
Copy link
Contributor

tzolov commented Nov 22, 2023

@JM-Lab as @making pointed out we can not expose proprietary libraries throughout the Spring AI public API.

Subclassing is not an option either. We need to define a new generic chunk interface or interfaces.
Also the Spring projects is somewhat biased toward Flux instead of rx.
Please share your design thoughts, apologies for not providing any guidelines so far.

Implement AiStreamClient interface extending AiClient,
Implement OpenAiStreamClient using Reactor Flux
@JM-Lab
Copy link
Contributor Author

JM-Lab commented Nov 26, 2023

Regarding the feedback from @tzolov, the development was revisited.
OpenAiStreamClient has been re-implemented to directly adhere to the latest Request/Response specifications of OpenAI's Chat Completion API.
Using Flux, the existing 'generate' method was re-implemented, and the 'generateStream' method was added.

The commit details are as follows:

  • Add the latest Request and Response Classes of OpenAI's Chat Completion API
  • Add the spring-boot-starter-webflux dependency
  • Implement the AiStreamClient interface extending AiClient
  • Implement OpenAiStreamClient using Reactor Flux

If you have any additional inquiries or recommendations, please don't hesitate to reach out.

@XYWENJIE
Copy link

XYWENJIE commented Dec 1, 2023

Sorry, I didn't see this issue before. Just finished reading the code, thank you for sharing.

I recently encountered this issue with SSE requests when accessing other LLM products using Spring AI. Just implement the function yourself.

After reading this code, I think it has great reference value

@tzolov
Copy link
Contributor

tzolov commented Dec 12, 2023

Rebased, squashed and merged at 8139af4
@JM-Lab thank you for the contribution and expect a follow-up changes as I'm heavily refactoring the chat generation and embedding clients.

@tzolov tzolov closed this Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stream support in AiClient

4 participants